# -*- coding:utf-8 -*-
from __future__ import unicode_literals

from django.db import models

# Create your models here.

class Author(models.Model):
    auth_name = models.CharField(max_length=32,null=False,verbose_name=u'作者姓名')
    telephone = models.CharField(max_length=11,verbose_name=u'联系电话')
    email = models.EmailField(verbose_name=u'邮箱地址')

    def __unicode__(self):
        return "%s" % (self.auth_name)

    class Meta:
        db_table = 'book_author'
        verbose_name = u'作者信息表'
        verbose_name_plural = verbose_name

class Publisher(models.Model):
    name = models.CharField(max_length=64,verbose_name=u'出版社名')
    address = models.CharField(max_length=255,verbose_name=u'联系地址')
    telephone = models.CharField(max_length=11,verbose_name=u'联系电话')
    city = models.CharField(max_length=64,verbose_name=u'所在城市')
    website = models.URLField(verbose_name=u'官方网站')

    def __unicode__(self):
        return '%s' %(self.name)

    class Meta:
        db_table = 'book_publisher'
        verbose_name = u'出版社信息表'
        verbose_name_plural = verbose_name

class Books(models.Model):
    book_name = models.CharField(max_length=64,null=False,verbose_name=u'书名')
    price = models.DecimalField(max_digits=8,decimal_places=2,verbose_name=u'价格')
    amount = models.SmallIntegerField(verbose_name=u'库存数量')
    author = models.ManyToManyField(Author,verbose_name='作者')
    publisher = models.ForeignKey(Publisher,verbose_name='出版社')
    publish_date = models.DateField(auto_now_add=True,verbose_name=u'出版时间')

    def __unicode__(self):
        return '<%s-%s-%s-%s-%s>' %(self.book_name, self.author, self.price, self.publisher, self.publish_date)

    class Meta:
        db_table = 'books_info'
        verbose_name = u'书籍信息'
        verbose_name_plural = verbose_name
